import { api } from '@/axios/instance';
import { toast } from 'sonner';

type PostResponseProject = PostRequest & { data: ProjectListItem };

type ProjectRequest = PostRequest & { data: ProjectList };
export const getProjectList = async (requestConfig?: AxiosRequestConfig) =>
  api
    .post<ProjectRequest>('/api/TaskBoard/projectList', requestConfig?.config)
    .then((res) => res.data.data);

type PostProjectConfig = AxiosRequestConfig<{ name: string; description?: string }>;
export const createProject = async ({ params, config }: PostProjectConfig) =>
  api.post<PostResponseProject>('/api/TaskBoard/projectCreate', params, config).then((response) => {
    if (response.data.success === 'ok') {
      toast.success('Project Created 👌🏼!');
      return response.data;
    }
    return response.data;
  });

type PostDeleteProjectConfig = AxiosRequestConfig<{ project_id: string }>;
export const deleteProject = async ({ params, config }: PostDeleteProjectConfig) =>
  api.post('/api/TaskBoard/projectDelete', params, config).then((response) => {
    if (response.data.success === 'ok') {
      toast.success('Project Deleted 👌🏼!');
      return 'ok';
    }
  });
